﻿using Sunboxsoft.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Domain = Sunboxsoft.ASMS.Server.Domain;
using Entity = Sunboxsoft.ASMS.Server.Domain.Entity;
using View = Sunboxsoft.ASMS.Server.Domain.View;
using Data = Sunboxsoft.ASMS.Server.Domain.Data;
using Service = Sunboxsoft.ASMS.Server.Domain.Service;

namespace Sunboxsoft.ASMS.Web.Services
{
    /// <summary>
    /// ASMSWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class ASMSWebService : System.Web.Services.WebService
    {
        [WebMethod]
        public ServiceResult DeleteBookingBill(Guid id)
        {
            return new Service.DeleteService().DeleteBookingBill(id);
        }

        [WebMethod]
        public ServiceResult DeleteWorkingBill(Guid maintenanceBillId, Guid maintenanceBillServiceItemId)
        {
            return new Service.DeleteService().DeleteWorkingBill(maintenanceBillId, maintenanceBillServiceItemId);
        }

        [WebMethod]
        public SingleResult<Entity.ECustomer> CreateCustomer(Entity.ECustomer customer)
        {
            return new Service.CreateService().CreateCustomer(customer);
        }

        [WebMethod]
        public ServiceResult CreateAutomobile(Entity.EAutomobile automobile)
        {
            return new Service.CreateService().CreateAutomobile(automobile);
        }

        [WebMethod]
        public ServiceResult CreateBookingBill(Entity.EBookingBill bill, Entity.EBookingService[] services)
        {
            return new Service.CreateService().CreateBookingBill(bill, services);
        }

        [WebMethod]
        public PagedResult<View.VCustomer> QueryCustomerPagedList(string filter, int start, int limit)
        {
            return new Service.QueryService().QueryCustomerPagedList(filter, start, limit);
        }

        [WebMethod]
        public ListResult<View.VAutomobile> QueryAutomobileList(Guid customerId)
        {
            return new Service.QueryService().QueryAutomobileList(customerId);
        }

        [WebMethod]
        public PagedResult<View.VBookingBill> QueryBookingBillPagedList(Guid businessId, Guid stationId, DateTime? beginDate, DateTime? endDate, Guid? salesManagerId, int status, int start, int limit)
        {
            return new Service.QueryService().QueryBookingBillPagedList(businessId, stationId, beginDate, endDate, salesManagerId, status, start, limit);
        }

        [WebMethod]
        public ListResult<View.VStaffPosition> QueryStaffPositionList(string filter, Guid businessId, Guid? stationId, string post)
        {
            return new Service.QueryService().QueryStaffPositionList(filter, businessId, stationId, post);
        }

        [WebMethod]
        public ListResult<View.VStation> QueryStationListByStaff(Guid staffId)
        {
            return new Service.QueryService().QueryStationListByStaff(staffId);
        }

        [WebMethod]
        public PagedResult<Entity.EStaff> QueryStaffPagedList(string filter, Guid businessId, Guid stationId, int status, int start, int limit)
        {
            return new Service.QueryService().QueryStaffPagedList(filter, businessId, stationId, status, start, limit);
        }
        #region service item
        [WebMethod]
        public PagedResult<Entity.EServiceCategory> QueryServiceCategoryPagedList(Guid? businessId, Guid? stationId, int status, int start, int limit)
        {
            return new Service.QueryService().QueryServiceCategoryPagedList(businessId, stationId, status, start, limit);
        }

        [WebMethod]
        public PagedResult<View.VServiceItem> QueryServiceItemPagedList(string filter, Guid? categoryId, Guid? businessId, Guid? stationId, int status, int start, int limit)
        {
            return new Service.QueryService().QueryServiceItemPagedList(filter, categoryId, businessId, stationId, status, start, limit);
        }

        [WebMethod]
        public ServiceResult CreateServiceItem(Entity.EServiceItem item)
        {
            return new Service.CreateService().CreateServiceItem(item);
        }

        [WebMethod]
        public ServiceResult CreateServiceCategory(Entity.EServiceCategory category)
        {
            return new Service.CreateService().CreateServiceCategory(category);
        }

        #endregion

        [WebMethod]
        public ListResult<Entity.EMasterData> QueryMasterDataList()
        {
            return new Domain.Service.QueryService().QueryMasterDataList();
        }

        [WebMethod]
        public ListResult<Entity.EMasterDataItem> QueryMasterDataItemList(string masterDataCode)
        {
            return new Domain.Service.QueryService().QueryMasterDataItemList(masterDataCode);
        }

        [WebMethod]
        public ServiceResult CreatePayItem(Entity.EPayItem payItem)
        {
            return new Domain.Service.CreateService().CreatePayItem(payItem);
        }

        [WebMethod]
        public PagedResult<Entity.EPayItem> QueryPayItemPagedList(Guid? businessId, Guid? stationId, int status, int start, int limit)
        {
            return new Domain.Service.QueryService().QueryPayItemPagedList(businessId, stationId, status, start, limit);
        }

        [WebMethod]
        public ServiceResult UpdateAutomobile(Guid id, Entity.EAutomobile automobile)
        {
            return new Domain.Service.UpdateService().UpdateAutomobile(id, automobile);
        }

        [WebMethod]
        public ServiceResult UpdateBookingBill(Guid id, Entity.EBookingBill bookingBill, Entity.EBookingService[] serviceArray)
        {
            return new Domain.Service.UpdateService().UpdateBookingBill(id, bookingBill, serviceArray);
        }

        [WebMethod]
        public ServiceResult UpdateCustomer(Guid id, Entity.ECustomer customer)
        {
            return new Domain.Service.UpdateService().UpdateCustomer(id, customer);
        }

        [WebMethod]
        public SingleResult<Entity.EMaterial> CreateMaterial(Entity.EMaterial material)
        {
            return new Domain.Service.CreateService().CreateMaterial(material);
        }

        [WebMethod]
        public PagedResult<View.VMaterial> QueryMaterialPagedList(string filter, Guid? businessId, Guid? stationId, string category, string brand, int status, int start, int limit)
        {
            return new Domain.Service.QueryService().QueryMaterialPagedList(filter, businessId, stationId, category, brand, status, start, limit);
        }

        [WebMethod]
        public ListResult<View.VMaterialWithStock> QueryMaterialWithStockList(Guid businessId, Guid stationId, Guid materialId)
        {
            return new Domain.Service.QueryService().QueryMaterialWithStockList(businessId, stationId, materialId);
        }

        [WebMethod]
        public PagedResult<View.VStockMaterial> QueryStockMaterialPagedList(string filter, Guid? businessId, Guid? stationId, Guid? warehouseId, string category, string brand, int status, int start, int limit)
        {
            return new Domain.Service.QueryService().QueryStockMaterialPagedList(filter, businessId, stationId, warehouseId, category, brand, status, start, limit);
        }

        [WebMethod]
        public ServiceResult CreateWarehouse(Entity.EWarehouse warehouse)
        {
            return new Domain.Service.CreateService().CreateWarehouse(warehouse);
        }

        [WebMethod]
        public PagedResult<View.VWarehouse> QueryWarehousePagedList(string filter, Guid? businessId, Guid? stationId, int status, int start, int limit)
        {
            return new Domain.Service.QueryService().QueryWarehousePagedList(filter, businessId, stationId, status, start, limit);
        }

        [WebMethod]
        public ServiceResult CreateStockIncreaseBill(Entity.EStockIncreaseBill bill, Entity.EStockIncreaseBillItem[] itemArray)
        {
            return new Domain.Service.CreateService().CreateStockIncreaseBill(bill, itemArray);
        }

        [WebMethod]
        public ServiceResult CreateStockDecreaseBill(Entity.EStockDecreaseBill bill, Entity.EStockDecreaseBillItem[] itemArray)
        {
            return new Domain.Service.CreateService().CreateStockDecreaseBill(bill, itemArray);
        }

        [WebMethod]
        public ServiceResult CreateStockThresholdValue(Entity.EStockThresholdValue thresholdValue)
        {
            return new Domain.Service.CreateService().CreateStockThresholdValue(thresholdValue);
        }

        [WebMethod]
        public ServiceResult UpdateStockThresholdValue(Entity.EStockThresholdValue thresholdValue)
        {
            return new Domain.Service.UpdateService().UpdateStockThresholdValue(thresholdValue);
        }

        [WebMethod]
        public SingleResult<View.VStockThresholdValue> GetStockThresholdValue(Guid warehouseId, Guid materialId)
        {
            return new Service.GetService().GetStockThresholdValue(warehouseId, materialId);
        }

        [WebMethod]
        public SingleResult<View.VWarehouse> GetWarehouse(Guid id)
        {
            return new Service.GetService().GetWarehouse(id);
        }

        [WebMethod]
        public PagedResult<View.VStockChangedRecord> QueryStockChangedRecordPagedList(Guid? businessId, Guid? stationId, Guid? warehouseId, Guid? materialId, DateTime? beginTime, DateTime? endTime, int type, int start, int limit)
        {
            return new Domain.Service.QueryService().QueryStockChangedRecordPagedList(businessId, stationId, warehouseId, materialId, beginTime, endTime, type, start, limit);
        }

        [WebMethod]
        public PagedResult<View.VStock> QueryStockPagedList(string filter, int queryType, Guid? businessId, Guid? stationId, Guid? warehouseId, Guid? materialId, string category, int start, int limit)
        {
            return new Service.QueryService().QueryStockPagedList(filter, queryType, businessId, stationId, warehouseId, materialId, category, start, limit);
        }

        [WebMethod]
        public PagedResult<Data.StockWarning> QueryStockWarningPagedList(Guid? businessId, Guid? stationId, Guid? warehouseId, Guid? materialId, int start, int limit)
        {
            return new Service.QueryService().QueryStockWarningPagedList(businessId, stationId, warehouseId, materialId, start, limit);
        }

        [WebMethod]
        public ServiceResult CreateSupplier(Entity.ESupplier supplier)
        {
            return new Service.CreateService().CreateSupplier(supplier);
        }

        [WebMethod]
        public PagedResult<View.VSupplier> QuerySupplierPagedList(string filter, Guid? businessId, Guid? stationId, int status, int start, int limit)
        {
            return new Service.QueryService().QuerySupplierPagedList(filter, businessId, stationId, status, start, limit);
        }

        [WebMethod]
        public SingleResult<decimal> GetAsset(Guid customerId, int assetType)
        {
            return new Service.GetService().GetAsset(customerId, assetType);
        }

        [WebMethod]
        public SingleResult<Data.BookingBillDetail> GetBookingBillDetail(Guid id)
        {
            return new Service.GetService().GetBookingBillDetail(id);
        }

        [WebMethod]
        public SingleResult<View.VCustomer> GetCustomer(Guid id)
        {
            return new Service.GetService().GetCustomer(id);
        }

        #region maintenanceBill
        [WebMethod]
        public SingleResult<Entity.EMaintenanceBill> CreateMaintenanceBill(Entity.EMaintenanceBill bill, Entity.EMaintenanceBillServiceItem[] serviceItemArray,
            Entity.EMaintenanceBillMaterial[] materialArray,
            Entity.EMaintenanceBillPayItem[] payItemArray)
        {
            return new Service.CreateService().CreateMaintenanceBill(bill, serviceItemArray, materialArray, payItemArray);
        }

        [WebMethod]
        public PagedResult<View.VMaintenanceBill> QueryMaintenanceBillPageList(string filter, DateTime? beginTime, DateTime? endTime, Guid? businessId, Guid? stationId, int[] statusArray, int[] serviceItemStatusArray, int[] materialStatusArray, int start, int limit)
        {
            return new Service.QueryService().QueryMaintenanceBillPageList(filter, beginTime, endTime, businessId, stationId, statusArray, serviceItemStatusArray, materialStatusArray, start, limit);
        }

        [WebMethod]
        public SingleResult<Data.MaintenanceBillDetail> GetMaintenanceBillDetail(Guid id)
        {
            return new Service.GetService().GetMaintenanceBillDetail(id);
        }
        #endregion

        #region working bill

        /// <summary>
        /// 创建派工单
        /// </summary>
        /// <param name="bill"></param>
        /// <returns></returns>
        [WebMethod]
        public ServiceResult CreateWorkingBill(Entity.EWorkingBill bill)
        {
            return new Service.CreateService().CreateWorkingBill(bill);
        }

        /// <summary>
        /// 更新派工单到完成状态
        /// </summary>
        /// <param name="maintenanceBillId"></param>
        /// <param name="maintenanceBillServiceItemId"></param>
        /// <returns></returns>
        [WebMethod]
        public ServiceResult UpdateWorkingBillToFinished(Guid maintenanceBillId, Guid maintenanceBillServiceItemId)
        {
            return new Service.UpdateService().UpdateWorkingBillToFinished(maintenanceBillId, maintenanceBillServiceItemId);
        }
        #endregion

        [WebMethod]
        public ServiceResult UpdateWarehouse(Guid id, Entity.EWarehouse warehouse)
        {
            return new Service.UpdateService().UpdateWarehouse(id, warehouse);
        }

        #region material requisition bill
        /// <summary>
        /// 创建领料单
        /// </summary>
        /// <param name="bill"></param>
        /// <returns></returns>
        [WebMethod]
        public ServiceResult CreateMaterialRequisitionBill(Entity.EMaterialRequisitionBill bill)
        {
            return new Service.CreateService().CreateMaterialRequisitionBill(bill);
        }

        #endregion
        /// <summary>
        /// 创建退料单
        /// </summary>
        /// <param name="bill"></param>
        /// <returns></returns>
        [WebMethod]
        public ServiceResult CreateMaterialReturnedBill(Entity.EMaterialReturnedBill bill)
        {
            return new Service.CreateService().CreateMaterialReturnedBill(bill);
        }

        #region business and station
        /// <summary>
        /// 获取商家Id
        /// </summary>
        /// <returns></returns>
        [WebMethod]
        public ListResult<Entity.EBusiness> QueryBusinessList()
        {
            return new Service.QueryService().QueryBusinessList();
        }

        [WebMethod]
        public ListResult<View.VStation> QueryStationList(Guid? businessId, Guid? stationId)
        {
            return new Service.QueryService().QueryStationList(businessId, stationId);
        }
        #endregion

        #region PackagePurchaseBill

        [WebMethod]
        public ServiceResult CheckOutPackagePurchaseBill(Guid billId, Data.CheckOutData checkOutData, Entity.EPayRecord[] payRecordArray)
        {
            return new Service.CheckOutService().CheckOutPackagePurchaseBill(billId, checkOutData, payRecordArray);
        }

        [WebMethod]
        public SingleResult<Entity.EPackagePurchaseBill> CreatePackagePurchaseBill(Entity.EPackagePurchaseBill bill)
        {
            return new Service.CreateService().CreatePackagePurchaseBill(bill);
        }

        [WebMethod]
        public ServiceResult CreatePackage(Entity.EPackage package, Entity.ESalesPrice[] priceArray, Entity.EPackageItem[] itemArray, Entity.EPackageScope[] scopeArray)
        {
            return new Service.CreateService().CreatePackage(package, priceArray, itemArray, scopeArray);
        }

        [WebMethod]
        public PagedResult<Entity.EPackage> QueryPackagePagedList(string filter, Guid? businessId, Guid? stationId, int status, int start, int limit)
        {
            return new Service.QueryService().QueryPackagePagedList(filter, businessId, stationId, status, start, limit);
        }

        [WebMethod]
        public PagedResult<View.VPackageInstanceItemChangedRecord> QueryPackageInstanceItemChangedRecordPagedList(Guid? customerId, int start, int limit)
        {
            return new Service.QueryService().QueryPackageInstanceItemChangedRecordPagedList(customerId, start, limit);
        }

        [WebMethod]
        public ListResult<Entity.EPackageItem> QueryPackageItemList(Guid packageId)
        {
            return new Service.QueryService().QueryPackageItemList(packageId);
        }

        [WebMethod]
        public ListResult<Entity.ESalesPrice> QuerySalePriceList(Guid targetId, int targetType)
        {
            return new Service.QueryService().QuerySalePriceList(targetId, targetType);
        }

        [WebMethod]
        public PagedResult<View.VPackagePurchaseBill> QueryPackagePurchaseBill(string filter, Guid? businessId, Guid? stationId, Guid? customerId, Guid? salesManagerId, int status, int start, int limit)
        {
            return new Service.QueryService().QueryPackagePurchaseBill(filter, businessId, stationId, customerId, salesManagerId, status, start, limit);
        }

        [WebMethod]
        public SingleResult<View.VPackagePurchaseBill> GetPackagePurchaseBill(Guid id)
        {
            return new Service.GetService().GetPackagePurchaseBill(id);
        }

        [WebMethod]
        public ListResult<Data.PackageInstanceDetail> QueryEnabledPackageInstanceList(Guid businessId, Guid stationId, Guid customerId)
        {
            return new Service.QueryService().QueryEnabledPackageInstanceList(businessId, stationId, customerId);
        }
        #endregion

        #region settlement

        [WebMethod]
        public SingleResult<Guid> CreateSettlementBill(Entity.ESettlementBill bill, Entity.ESettlementBillServiceItem[] serviceItemArray,
            Entity.ESettlementBillMaterial[] materailArray, Entity.ESettlementBillPayItem[] payItemArray,
            Entity.ESettlementBillPackageItem[] packageItemArray, Entity.ESettlementBillCoupon[] couponArray)
        {
            return new Service.CreateService().CreateSettlementBill(bill, serviceItemArray, materailArray, payItemArray, packageItemArray, couponArray);
        }

        [WebMethod]
        public ServiceResult CheckOutSettlementBill(Guid billId, Data.CheckOutData checkOutData, Entity.EPayRecord[] payRecordArray)
        {
            return new Service.CheckOutService().CheckOutSettlementBill(billId, checkOutData, payRecordArray);
        }

        [WebMethod]
        public SingleResult<Data.SettlementBillDetail> GetSettlementBillDetail(Guid id)
        {
            return new Service.GetService().GetSettlementBillDetail(id);
        }

        [WebMethod]
        public SingleResult<Data.SettlementBillDetail> GetSettlementBillDetailByMaintennanceBillId(Guid id)
        {
            return new Service.GetService().GetSettlementBillDetailByMaintennanceBillId(id);
        }
        #endregion

        #region recharge bill

        [WebMethod]
        public SingleResult<View.VRechargeBill> GetRechargeBill(Guid id)
        {
            return new Service.GetService().GetRechargeBill(id);
        }

        [WebMethod]
        public ServiceResult CreateRechargeItem(Entity.ERechargeItem item)
        {
            return new Service.CreateService().CreateRechargeItem(item);
        }

        [WebMethod]
        public SingleResult<Guid> CreateRechargeBill(Entity.ERechargeBill bill)
        {
            return new Service.CreateService().CreateRechargeBill(bill);
        }

        [WebMethod]
        public PagedResult<View.VRechargeBill> QueryRechargeBillPagedList(Guid? customerId, Guid? businessId, Guid? stationId, int status, int start, int limit)
        {
            return new Service.QueryService().QueryRechargeBillPagedList(customerId, businessId, stationId, status, start, limit);
        }

        [WebMethod]
        public PagedResult<Entity.ERechargeItem> QueryRechargeItemPagedList(Guid? businessId, Guid? stationId, int status, int start, int limit)
        {
            return new Service.QueryService().QueryRechargeItemPagedList(businessId, stationId, status, start, limit);
        }

        [WebMethod]
        public ServiceResult CheckOutRechargeBill(Guid billId, Data.CheckOutData checkOutData, Entity.EPayRecord[] payRecordArray)
        {
            return new Service.CheckOutService().CheckOutRechargeBill(billId, checkOutData, payRecordArray);
        }
        #endregion

        [WebMethod]
        public ServiceResult DeliverMaintenanceBill(Guid maintenanceBillId)
        {
            return new Service.DeliverService().DeliverMaintenanceBill(maintenanceBillId);
        }

        #region capital

        [WebMethod]
        public ServiceResult CreateCapticalIncreaseBill(Entity.ECapitalIncreaseBill bill, Entity.EPayRecord[] payRecordArray)
        {
            return new Service.CreateService().CreateCapticalIncreaseBill(bill, payRecordArray);
        }

        [WebMethod]
        public ServiceResult CreateCapticalDecreaseBill(Entity.ECapitalDecreaseBill bill, Entity.EPayRecord[] payRecordArray)
        {
            return new Service.CreateService().CreateCapticalDecreaseBill(bill, payRecordArray);
        }

        [WebMethod]
        public PagedResult<View.VCapitalIncreaseBill> QueryCapitalIncreaseBillPagedList(Guid? businessId, Guid? stationId, DateTime? beginTime, DateTime? endTime, int changedType, int start, int limit)
        {
            return new Service.QueryService().QueryCapitalIncreaseBillPagedList(businessId, stationId, beginTime, endTime, changedType, start, limit);
        }

        [WebMethod]
        public PagedResult<View.VCapitalDecreaseBill> QueryCapitalDecreaseBillPagedList(Guid? businessId, Guid? stationId, DateTime? beginTime, DateTime? endTime, int changedType, int start, int limit)
        {
            return new Service.QueryService().QueryCapitalDecreaseBillPagedList(businessId, stationId, beginTime, endTime, changedType, start, limit);
        }

        [WebMethod]
        public PagedResult<View.VCapitalChangedRecord> QueryCapitalChangedRecordPagedList(Guid? businessId, Guid? stationId, DateTime? beginTime, DateTime? endTime, int changedType, string payChannel, int start, int limit)
        {
            return new Service.QueryService().QueryCapitalChangedRecordPagedList(businessId, stationId, beginTime, endTime, changedType, payChannel, start, limit);
        }
        #endregion

        [WebMethod]
        public ListResult<Entity.EBillHeader> QueryBillHeaderList(string billNumber)
        {
            return new Service.QueryService().QueryBillHeaderList(billNumber);
        }

        [WebMethod]
        public SingleResult<Entity.ERechargeItem> GetRechargeItem(Guid id)
        {
            return new Service.GetService().GetRechargeItem(id);
        }
    }
}
